home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus Leser 15 / Amiga Plus Leser CD 15.iso / Tools / Development / ScoutSource / source / objects / scout_commodity.c < prev    next >
Encoding:
C/C++ Source or Header  |  2002-03-13  |  15.7 KB  |  512 lines

  1. /**
  2.  * Scout - The Amiga System Monitor
  3.  *
  4.  *------------------------------------------------------------------
  5.  *
  6.  * This program is free software; you can redistribute it and/or modify
  7.  * it under the terms of the GNU General Public License as published by
  8.  * the Free Software Foundation; either version 2 of the License, or
  9.  * any later version.
  10.  *
  11.  * This program is distributed in the hope that it will be useful,
  12.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.  * GNU General Public License for more details.
  15.  *
  16.  * You should have received a copy of the GNU General Public License
  17.  * along with this program; if not, write to the Free Software
  18.  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  19.  *
  20.  * You must not use this source code to gain profit of any kind!
  21.  *
  22.  *------------------------------------------------------------------
  23.  *
  24.  * @author Andreas Gelhausen
  25.  * @author Richard Körber <rkoerber@gmx.de>
  26.  */
  27.  
  28.  
  29.  
  30. #include "system_headers.h"
  31.  
  32. int  cxcnt;
  33.  
  34. static APTR cxmoretext0,cxmoretext1,cxmoretext2,cxmoretext3,cxmoretext4,cxmoretext5;
  35. static APTR cxsublist;
  36.  
  37. static APTR CxPool = NULL;
  38.  
  39. static struct MyCxObj {
  40.    struct Node     mco_Node;
  41.    UBYTE           mco_Flags;
  42.    UBYTE           mco_dummy1;
  43.    struct MinList  mco_SubList;
  44.    APTR            mco_dummy2;
  45.    char            mco_Name[CBD_NAMELEN];
  46.    char            mco_Title[CBD_TITLELEN];
  47.    char            mco_Descr[CBD_DESCRLEN];
  48.    struct Task *   mco_Task;
  49.    struct MsgPort *mco_Port;
  50.    ULONG           mco_dummy3;
  51.    WORD            mco_dummy4;
  52. };
  53.  
  54. static char * GetCxNodeType (UBYTE type)
  55. {
  56.    char *CxNodeTypeText[] = {
  57.       "Invalid","Filter","Typefilter","Send",
  58.       "Signal","Translate","Broker","Debug",
  59.       "Custom","Zero","< ??? >"
  60.    };
  61.  
  62.    if(type>CX_ZERO)
  63.       return("< ??? >");
  64.    else
  65.       return(CxNodeTypeText[type]);
  66. }
  67.  
  68. __asm __saveds LONG cxlist_cmpprifunc (register __a1 struct CxEntry *ce1, register __a2 struct CxEntry *ce2)
  69. {
  70.    long  eins = 0, zwei = 0;
  71.  
  72.    IsDec (ce1->cxe_pri, &eins);
  73.    IsDec (ce2->cxe_pri, &zwei);
  74.  
  75.    return zwei - eins;
  76. }
  77.  
  78. struct Hook cxlist_cmpprihook = {
  79.  {NULL, NULL},
  80.  (ULONG (* )())cxlist_cmpprifunc,
  81.  NULL, NULL
  82. };
  83.  
  84. __asm __saveds LONG cxlist_cmpaddressfunc (register __a1 struct CxEntry *ce1, register __a2 struct CxEntry *ce2)
  85. {
  86.    return (LONG)ce1->cxe_adr - (LONG)ce2->cxe_adr;
  87. }
  88.  
  89. struct Hook cxlist_cmpaddresshook = {
  90.  {NULL, NULL},
  91.  (ULONG (* )())cxlist_cmpaddressfunc,
  92.  NULL, NULL
  93. };
  94.  
  95. __asm __saveds LONG cxlist_cmpnamefunc (register __a1 struct CxEntry *ce1, register __a2 struct CxEntry *ce2)
  96. {
  97.    return strcmpi(ce1->cxe_name, ce2->cxe_name);
  98. }
  99.  
  100. struct Hook cxlist_cmpnamehook = {
  101.  {NULL, NULL},
  102.  (ULONG (* )())cxlist_cmpnamefunc,
  103.  NULL, NULL
  104. };
  105.  
  106. __asm __saveds LONG cxlist_dspfunc(register __a2 char **array, register __a1 struct CxEntry *cxentry, register __a0 struct Hook *hook)
  107. {
  108.    if (cxentry) {
  109.       *array++ = cxentry->cxe_address;
  110.       *array++ = cxentry->cxe_type;
  111.       *array++ = cxentry->cxe_pri;
  112.       *array++ = cxentry->cxe_flags;
  113.       *array++ = cxentry->cxe_port;
  114.       *array   = cxentry->cxe_name;
  115.    } else {
  116.       *array++ = ESC "bAddress";
  117.       *array++ = ESC "bln_Type";
  118.       *array++ = ESC "bln_Pri";
  119.       *array++ = ESC "bFlags";
  120.       *array++ = ESC "bPort";
  121.       *array   = ESC "bName";
  122.    }
  123.    return (0);
  124. }
  125.  
  126. struct Hook cxlist_dsphook = {
  127.  {NULL, NULL},
  128.  (ULONG (* )())cxlist_dspfunc,
  129.  NULL, NULL
  130. };
  131.  
  132. void FreeCx (void)
  133. {
  134.     MyFreePoolStructs(&CxPool, cxtext, NULL, cxlist);
  135. }
  136.  
  137. void GetCxEntry (struct CxEntry *cxentry, struct MyCxObj *bc) {
  138.  
  139.    if (! cxentry->cxe_adr) {
  140.       cxentry->cxe_adr = (char *)bc;
  141.  
  142.       _sprintf (cxentry->cxe_address, "$%08lx", bc);
  143.       strcpy (cxentry->cxe_type, GetCxNodeType (CxObjType((CxObj *)bc)));
  144.    }
  145.  
  146.    _sprintf (cxentry->cxe_pri, "%4ld ", bc->mco_Node.ln_Pri);
  147.    strcpy (cxentry->cxe_name, bc->mco_Name);
  148.    strcpy (cxentry->cxe_title, bc->mco_Title);
  149.    strcpy (cxentry->cxe_descr, bc->mco_Descr);
  150.    _sprintf (cxentry->cxe_task, "$%08lx", bc->mco_Task);
  151.    _sprintf (cxentry->cxe_port, "$%08lx", bc->mco_Port);
  152.    _sprintf (cxentry->cxe_unique, "$%08lx", bc->mco_dummy3);
  153.    cxentry->cxe_flags_int = bc->mco_Flags;
  154.    _sprintf (cxentry->cxe_flags, "$%02lx", bc->mco_Flags);
  155. }
  156.  
  157. int GetCx (struct CxEntry **first) {
  158.    struct   CxEntry   *cxentry,*previous = NULL;
  159.  
  160.    int cxcnt = 0;
  161.    *first = 0;
  162.  
  163.    if (!CxPool) CxPool = tbCreatePool(MEMF_CLEAR, 4096, 4096);
  164.  
  165.    if (clientstate) {
  166.       if (SendDaemon ("GetCxList")) {
  167.          while ((cxentry = tbAllocPooled(CxPool, sizeof(struct CxEntry))) \
  168.            && (ReceiveDecodedEntry ((UBYTE *) cxentry, sizeof (struct CxEntry)))) {
  169.             IsHex (cxentry->cxe_address, (long *) &cxentry->cxe_adr);
  170.  
  171.             if (! *first)
  172.                *first = cxentry;
  173.             if (previous)
  174.                previous->cxe_next = cxentry;
  175.  
  176.             cxcnt++;
  177.             previous = cxentry;
  178.          }
  179.       }
  180.    } else {
  181.       struct MsgPort *cxport;
  182.       struct NewBroker cxnewbroker =
  183.       {
  184.         NB_VERSION,
  185.         "« Scout Dummy »",
  186.         "« Scout Dummy »",
  187.         "Dummy Broker",
  188.         0,
  189.         0,
  190.         0,
  191.         NULL,
  192.         0
  193.       };
  194.       struct MyCxObj *cxbroker;
  195.       struct Node *broker;
  196.  
  197.       if(cxport = CreateMsgPort()) {
  198.          cxnewbroker.nb_Port = cxport;
  199.          if(cxbroker = (struct MyCxObj *)CxBroker(&cxnewbroker,NULL)) {
  200.             Forbid();
  201.               for(broker=&cxbroker->mco_Node; broker->ln_Pred; broker=broker->ln_Pred);   /* Search the list head */
  202.               for(broker=broker->ln_Succ; broker->ln_Succ; broker=broker->ln_Succ) {
  203.                  if(broker==(struct Node *)cxbroker) continue;                            /* Skip own dummy broker */
  204.                  if(cxentry = tbAllocPooled(CxPool, sizeof(struct CxEntry))) {
  205.                     GetCxEntry (cxentry,(struct MyCxObj *)broker);
  206.  
  207.                     if (! *first)
  208.                        *first = cxentry;
  209.                     if (previous)
  210.                        previous->cxe_next = cxentry;
  211.  
  212.                     cxcnt++;
  213.                     previous = cxentry;
  214.                  }
  215.               }
  216.             Permit();
  217.             DeleteCxObjAll((CxObj *)cxbroker);
  218.          }
  219.          DeleteMsgPort(cxport);
  220.       }
  221.    }
  222.    return (cxcnt);
  223. }
  224.  
  225. void PrintCx (char *filename) {
  226.    int   i=1;
  227.    BPTR  handle;
  228.    struct CxEntry *entryp = NULL;
  229.  
  230.    handle = HandlePrintStart (filename);
  231.    if ((handle) && (PrintOneLine (handle, "\n  Address  Type     Pri Flags  Port      Name\n\n"))) {
  232.       if (! WI_Cx) {
  233.          i = GetCx (&entryp);
  234.       }
  235.       if (i) {
  236.          for (i=0;;i++) {
  237.             if (WI_Cx)
  238.                DoMethod (cxlist,MUIM_List_GetEntry,i,&entryp);
  239.             if (!entryp) break;
  240.  
  241.             _sprintf (tmpstr2, " %s %-7.7s %3s %3s   %s %s\n", entryp->cxe_address, entryp->cxe_type, entryp->cxe_pri, entryp->cxe_flags, entryp->cxe_port, entryp->cxe_name);
  242.             if (! (PrintOneLine (handle, tmpstr2)))
  243.                break;
  244.  
  245.             if (! WI_Cx)
  246.                entryp = entryp->cxe_next;
  247.          }
  248.       }
  249.    }
  250.    HandlePrintStop();
  251. }
  252.  
  253. void ShowCx (void) {
  254.    struct   CxEntry   *cx;
  255.  
  256.    ApplicationSleep();
  257.    set(cxlist,MUIA_List_Quiet,TRUE);
  258.    set(cxlist,MUIA_List_CompareHook,cxlist_cmphook_ptr);
  259.    set(BT_CxRemove, MUIA_Disabled, TRUE);
  260.    set(BT_CxPriority, MUIA_Disabled, TRUE);
  261.    set(BT_CxMore, MUIA_Disabled, TRUE);
  262.    set(BT_CxAppear, MUIA_Disabled, TRUE);
  263.    set(BT_CxDisappear, MUIA_Disabled, TRUE);
  264.    set(BT_CxEnable, MUIA_Disabled, TRUE);
  265.    set(BT_CxDisable, MUIA_Disabled, TRUE);
  266.    set(BT_CxKill, MUIA_Disabled, TRUE);
  267.    set(BT_CxListChg, MUIA_Disabled, TRUE);
  268.    set(BT_CxUnique, MUIA_Disabled, TRUE);
  269.    FreeCx();
  270.  
  271.    cxcnt = GetCx (&cx);
  272.  
  273.    while (cx) {
  274.       InsertSortedEntry (cxlist, (APTR *) &cx);
  275.       cx = cx->cxe_next;
  276.    }
  277.  
  278.    SetCountText (cxcount, cxcnt);
  279.    AwakeApplication();
  280.    set(cxlist,MUIA_List_Quiet,FALSE);
  281. }
  282.  
  283. void SendCxList (void) {
  284.    struct   CxEntry   *cx;
  285.  
  286.    FreeCx();
  287.    GetCx (&cx);
  288.  
  289.    while (cx) {
  290.       SendEncodedEntry ((UBYTE *) cx, sizeof (struct CxEntry));
  291.       cx = cx->cxe_next;
  292.    }
  293.    FreeCx();
  294. }
  295.  
  296. __asm __saveds LONG cxmore_dspfunc(register __a2 char **array, register __a1 struct CxSubEntry *subentry, register __a0 struct Hook *hook)
  297. {
  298.    if (subentry) {
  299.       *array++ = subentry->cse_address;
  300.       *array++ = subentry->cse_type;
  301.       *array   = subentry->cse_pri;
  302.    } else {
  303.       *array++ = ESC "bAddress";
  304.       *array++ = ESC "bln_Type";
  305.       *array   = ESC "bln_Pri";
  306.    }
  307.    return (0);
  308. }
  309.  
  310. struct Hook cxmore_dsphook = {
  311.  {NULL, NULL},
  312.  (ULONG (* )())cxmore_dspfunc,
  313.  NULL, NULL
  314. };
  315.  
  316. void GetSubList (struct MyCxObj *cxo) {
  317.    struct CxSubEntry  *subentry;
  318.    struct Node *node;
  319.  
  320.    set(cxsublist,MUIA_List_Quiet,TRUE);
  321.  
  322.    for(node=(struct Node *)cxo->mco_SubList.mlh_Head; node->ln_Succ; node=node->ln_Succ)
  323.    {
  324.       if(subentry = tbAllocPooled(CxPool, sizeof(struct CxEntry))) {
  325.          _sprintf (subentry->cse_address, "$%08lx", node);
  326.          strcpy  (subentry->cse_type   , GetCxNodeType(CxObjType((CxObj *)node)));
  327.          _sprintf (subentry->cse_pri    , "%ld ", node->ln_Pri);
  328.  
  329.          InsertBottomEntry (cxsublist, (APTR *) &subentry);
  330.       }
  331.    }
  332.  
  333.    set(cxsublist,MUIA_List_Quiet,FALSE);
  334. }
  335.  
  336. void GetCxMore (struct MyCxObj *bc) {
  337.    unsigned char     *title = "COMMODITY: ";
  338.    struct   WinFree  *ptr;
  339.    struct MsgPort *cxport;
  340.    struct NewBroker cxnewbroker =
  341.    {
  342.      NB_VERSION,
  343.      "« Scout Dummy »",
  344.      "« Scout Dummy »",
  345.      "Dummy Broker",
  346.      0,
  347.      0,
  348.      0,
  349.      NULL,
  350.      0
  351.    };
  352.    struct MyCxObj *cxbroker;
  353.    struct Node *broker;
  354.    BOOL found = FALSE;
  355.  
  356.    if(cxport = CreateMsgPort()) {
  357.       cxnewbroker.nb_Port = cxport;
  358.       if(cxbroker = (struct MyCxObj *)CxBroker(&cxnewbroker,NULL)) {
  359.          Forbid();
  360.            for(broker=&cxbroker->mco_Node; broker->ln_Pred; broker=broker->ln_Pred);   /* Search the list head */
  361.            for(broker=broker->ln_Succ; broker->ln_Succ; broker=broker->ln_Succ) {
  362.               if(broker==(struct Node *)cxbroker) continue;                            /* Skip own dummy broker */
  363.               if(broker==(struct Node *)bc) {
  364.                  found = TRUE;
  365.                  break;
  366.               }
  367.            }
  368.          Permit();
  369.          DeleteCxObjAll((CxObj *)cxbroker);
  370.       }
  371.       DeleteMsgPort(cxport);
  372.    }
  373.  
  374.    if (found && (ptr = AllocWinFree())) {
  375.       ptr->wf_Window = (APTR) WindowObject,
  376.       MUIA_HelpNode, CommoditiesText,
  377.       MUIA_Window_ID, MakeDetailID('.','C','X','X'),
  378.       WindowContents, VGroup,
  379.          Child, ColGroup(2),
  380.             Child, MyLabel2 ("Name:"),
  381.             Child, cxmoretext0 = MyTextObject(),
  382.             Child, MyLabel2 ("Title:"),
  383.             Child, cxmoretext1 = MyTextObject(),
  384.             Child, MyLabel2 ("Descr:"),
  385.             Child, cxmoretext2 = MyTextObject(),
  386.          End,
  387.          Child, HGroup, MUIA_Group_SameWidth, TRUE,
  388.             Child, ColGroup(2),
  389.                Child, MyLabel2 ("Address:\nType:\nPri:\nTask:\nPort:"),
  390.                Child, cxmoretext3 = MyTextObject2(),
  391.                Child, MyLabel2 ("Flags:"),
  392.                Child, cxmoretext4 = KeyButtonF ('b', bc->mco_Flags),
  393.             End,
  394.             Child, ColGroup(2),
  395.                Child, MyLabel2 ("\nSub CxObj:\n\n\n\n"),
  396.                Child, cxsublist = ListviewObject,
  397.                   MUIA_Listview_Input, FALSE,
  398.                   MUIA_Listview_List, ListObject,
  399.                      MUIA_List_Format, "DELTA=8,DELTA=8 P=\33c,P=\33c",
  400.                      MUIA_List_Title, TRUE,
  401.                      MUIA_List_DisplayHook, &cxmore_dsphook,
  402.                      ReadListFrame,
  403.                   End,
  404.                   MUIA_CycleChain, TRUE,
  405.                End,
  406.             End,
  407.          End,
  408.          Child, HGroup,
  409.             Child, MyLabel2 ("TaskName:"),
  410.             Child, cxmoretext5 = MyTextObject(),
  411.          End,
  412.       End, End;
  413.  
  414.       if (ptr->wf_Window) {
  415.          MySetContents (cxmoretext0, "%s", bc->mco_Name);
  416.          MySetContents (cxmoretext1, "%s", bc->mco_Title);
  417.          MySetContents (cxmoretext2, "%s", bc->mco_Descr);
  418.          MySetContents (cxmoretext3, ESC "r$%08lx\n" ESC "c%s\n%ld\n" ESC "r$%08lx\n$%08lx", bc, GetCxNodeType(CxObjType((CxObj *)bc)),bc->mco_Node.ln_Pri, bc->mco_Task, bc->mco_Port);
  419.          MySetContentsHealed (cxmoretext5, "%s", nonetest (GetTaskName (bc->mco_Task)));
  420.  
  421.          GetSubList (bc);
  422.  
  423.          HandleFlagsButtonPressed (cxmoretext4, ptr, "(COMMODITY)", "Flags", bc->mco_Flags, (struct LongFlag *) &bc_flags, NULL, 'b');
  424.          HandleWindowOpen (ptr, title, bc->mco_Name);
  425.          set (ptr->wf_Window,MUIA_Window_ActiveObject,cxsublist);
  426.          HandleWindowClose (ptr);
  427.       }
  428.    }
  429. }
  430.  
  431.  
  432.  
  433. APTR CxSortList[] = {
  434.    &cxlist_cmpaddresshook,
  435.    &cxlist_cmpnamehook,
  436.    &cxlist_cmpprihook,
  437.    NULL
  438. };
  439.  
  440. static const char *CYA_CxSortText[] = {
  441.    "address",
  442.    "name",
  443.    "priority",
  444.    NULL
  445. };
  446.  
  447. APTR WI_Cx, cxlist, cxtext, cxcount, CY_CxSort;
  448. int  cxsortstate = 0;
  449. APTR BT_CxAppear, BT_CxDisappear, BT_CxEnable, BT_CxDisable, BT_CxKill, BT_CxListChg, BT_CxUnique;
  450. APTR BT_CxUpdate, BT_CxPrint, BT_CxPriority, BT_CxRemove, BT_CxMore, BT_CxExit;
  451.  
  452. static char cx_title[WINDOWTITLELEN];
  453.  
  454. void CxWindow (BOOL state) {
  455.    if (state) {
  456.       if (WI_Cx) {
  457.          ShowCx();
  458.       } else {
  459.          WI_Cx = WindowObject,
  460.          MUIA_Window_Title, MyGetWindowTitle (cx_title, "COMMODITIES"),
  461.          MUIA_HelpNode, CommoditiesText,
  462.          MUIA_Window_ID, MakeListID('C','D','I','T'),
  463.          WindowContents, VGroup,
  464.             Child, cxlist = MyListviewObject ("DELTA=8,DELTA=8 P=\33c,DELTA=8 P=\33c,DELTA=8 P=\33c,DELTA=8,",&cxlist_dsphook),
  465.             Child, MyBelowSortedListview (&cxtext, &cxcount, &CY_CxSort, CYA_CxSortText, cxsortstate),
  466.             Child, MyVSpace(2),
  467.             Child, VGroup,
  468.                Child, HGroup, MUIA_Group_SameSize, TRUE,
  469.                   Child, BT_CxAppear     = KeyButtonA (AppearText   ,ID_CXAPPEAR),
  470.                   Child, BT_CxDisappear  = KeyButtonA (DisappearText,ID_CXDISAPPEAR),
  471.                   Child, BT_CxEnable     = KeyButtonA (EnableText   ,ID_CXENABLE),
  472.                   Child, BT_CxDisable    = KeyButtonA (DisableText  ,ID_CXDISABLE),
  473.                   Child, BT_CxKill       = KeyButtonA (KillText     ,ID_CXKILL),
  474.                   Child, BT_CxListChg    = KeyButtonA (ListChgText  ,ID_CXLISTCHG),
  475.                   Child, BT_CxUnique     = KeyButtonA (UniqueText   ,ID_CXUNIQUE),
  476.                End,
  477.                Child, HGroup, MUIA_Group_SameSize, TRUE,
  478.                   Child, BT_CxUpdate     = KeyButtonA (UpdateText   ,ID_CXUPDATE),
  479.                   Child, BT_CxPrint      = KeyButtonA (PrintText    ,ID_CXPRINT),
  480.                   Child, BT_CxPriority   = KeyButtonA (PriorityText ,ID_CXPRIORITY),
  481.                   Child, BT_CxRemove     = KeyButtonA (RemoveText   ,ID_CXREMOVE),
  482.                   Child, BT_CxMore       = KeyButtonA (MoreText     ,ID_CXMORE),
  483.                   Child, BT_CxExit       = KeyButtonA (ExitText     ,ID_CXEXIT),
  484.                End,
  485.             End,
  486.          End, End;
  487.  
  488.          if (WI_Cx) {
  489.             DoMethod (AP_Scout,OM_ADDMEMBER,WI_Cx);
  490.             DoMethod (WI_Cx,MUIM_Window_SetCycleChain,cxlist,CY_CxSort,BT_CxAppear,BT_CxDisappear,BT_CxEnable,BT_CxDisable,BT_CxKill,BT_CxListChg,BT_CxUnique,BT_CxUpdate,BT_CxPrint,BT_CxPriority,BT_CxRemove,BT_CxMore,BT_CxExit,NULL);
  491.             DoMethod (CY_CxSort, MUIM_Notify, MUIA_Cycle_Active, MUIV_EveryTime, AP_Scout, 2, MUIM_Application_ReturnID, ID_CXSORT);
  492.  
  493.             SetCloseRequest (WI_Cx,ID_CXEXIT);
  494.             SetListActive (cxlist,ID_CXLV_ACTIVE);
  495.             SetListviewDoubleClick (cxlist,ID_CXMORE);
  496.  
  497.             ShowCx();
  498.  
  499.             SetWindowOpen (WI_Cx,cxlist,ID_CXEXIT);
  500.          }
  501.       }
  502.    } else if ((! state) && (WI_Cx)) {
  503.       SetWindowClose (WI_Cx,TRUE);
  504.       FreeCx();
  505.       DoMethod (AP_Scout,OM_REMMEMBER,WI_Cx);
  506.       MUI_DisposeObject (WI_Cx);
  507.       WI_Cx = NULL;
  508.       cxlist = NULL;
  509.    }
  510. }
  511.  
  512.